POV-Ray : Newsgroups : povray.general : Re: Probably been asked... Why no power operator? : Re: Probably been asked... Why no power operator? Server Time
5 Aug 2024 14:19:06 EDT (-0400)
  Re: Probably been asked... Why no power operator?  
From: Slime
Date: 14 Nov 2002 17:29:35
Message: <3dd423cf$1@news.povray.org>
> Um, no. In algebra, there is no precedence, the exponent is in
> superscript, so there is no ambiguity. A plain text programming language
> doesn't have this, an operator has to be used, so it has to pick a
> precedence. I don't know what you were taught...


I was taught that

-(3^2) = -3^2

and that

(-3)^2 != -3^2

Of course, when it was written on a chalkboard, instead of "^2", the teacher
wrote a superscripted 2. But the meaning is identical. Just because we omit
the operator itself when we write it with pencil and paper doesn't mean that
the *operation* doesn't exist. The importance is in the order of operations,
and those go:

1. exponentiation
2. multiplication/division
3. addition/subtraction

Unary negation exists in the 3rd group. The only problem is when you have
something like

2*-3

because then you have two operators in a row. For convenience, this is
assumed to be 2*(-3), since that's the only possible meaning that can be
derived from it.

Similarly, 3^-2 should be considered 3^(-2), since that's the only possible
interpretation.

The debate is over what happens in this case:

-a(operator)b

In the case of multiplication, the order doesn't matter; the result is the
same either way. But in the case of exponentiation, the order *does* matter,
and the negation should happen second.

What could be said is that the negation happens second in the case of
multiplication, also, but since the result is the same, no one knows the
difference. And the only reason it happens first in the case of
a(operator)-b is because that's nothing more than a shortcut for
a(operator)(-b), as there is no other interpretation of the expression.

So that's my argument for why unary negation should happen along with
addition/subtraction, except in the cases where parenthesis are being
dropped.

 - Slime
[ http://www.slimeland.com/ ]


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.